package com.dp.client.views.reportesCharts;

import org.moxieapps.gwt.highcharts.client.*;  
import org.moxieapps.gwt.highcharts.client.labels.*;  
import org.moxieapps.gwt.highcharts.client.plotOptions.*; 

public class CrearStackedColumns {
	private Chart chart;
	private Point [] pointsLow;
	private Point [] pointsHigh;
	private String nombre;
	private String tipo;
	private String labelY;
	private String [] labels;
	
	public CrearStackedColumns(Point [] pointsLow,Point [] pointsHigh,String nombre,String tipo,String labelY){
		this.pointsLow=pointsLow;
		this.pointsHigh=pointsHigh;
		this.nombre=nombre;
		this.tipo=tipo;
		this.labelY=labelY;
		labels= new String[pointsLow.length];
		for (int i=0;i<pointsLow.length;i++)
			labels[i]=pointsLow[i].getName();
		init();
	}
	public void init(){
		chart = new Chart()  
        .setType(Series.Type.COLUMN)  
        .setChartTitleText(nombre)  
        .setColumnPlotOptions(new ColumnPlotOptions()  
            .setStacking(PlotOptions.Stacking.NORMAL)  
            .setDataLabels(new DataLabels()  
                .setEnabled(true)  
                .setColor("#FFFFFF")  
            )  
        )  
        .setLegend(new Legend()  
            .setAlign(Legend.Align.RIGHT)  
            .setVerticalAlign(Legend.VerticalAlign.TOP)  
            .setX(-100)  
            .setY(20)  
            .setFloating(true)  
            .setBackgroundColor("#FFFFFF")  
            .setBorderColor("#CCC")  
            .setBorderWidth(1)  
            .setShadow(false)  
        )  
        .setToolTip(new ToolTip()  
            .setFormatter(new ToolTipFormatter() {  
                public String format(ToolTipData toolTipData) {  
                    return "<b>" + toolTipData.getXAsString() + "</b><br/>" +  
                        toolTipData.getSeriesName() + ": " + toolTipData.getYAsLong() + "<br/>" +  
                        "Total: " + toolTipData.getTotalAsLong();  
                }  
            })  
        );  

	    chart.getXAxis()  
	        .setCategories(labels);  
	
	    chart.getYAxis()  
	        .setMin(0)  
	        .setAxisTitleText(labelY)  
	        .setStackLabels(new StackLabels()  
	            .setEnabled(true)  
	            .setStyle(new Style()  
	                .setFontWeight("bold")  
	                .setColor("gray")  
	            )  
	        );  
	
	    chart.addSeries(chart.createSeries()  
	        .setName("Vacio")  
	        .setPoints(pointsHigh)  
	    );  
	    chart.addSeries(chart.createSeries()  
	        .setName("Lleno")  
	        .setPoints(pointsLow)  
	    );  
	    
		}
	public Chart getChart(){
		return chart;
	}
}
